package zekezang.org;

import common.utils.activity.ActivityUtils;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class TabAppCenterActivity extends Activity {
	
	private static WebView webView = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tab_navigate_activity);
		
		webView = (WebView) findViewById(R.id.myNavigateWebView);
		
		init();
		
		String s = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'></head><body>ddsdsds</br>" +
				"<a href='http://www.sina.com.cn/'>dd</a>" +
				"ddddddd</body></html>";
		webView.loadData(s, "text/html", "utf-8");
	}
	
	private void init() {// 初始化

		webView.setClickable(true);
		webView.getSettings().setJavaScriptEnabled(true);// 可用JS

		// Enum for specifying the WebView's desired density. FAR makes 100%
		// looking like in 240dpi MEDIUM makes 100% looking like in 160dpi CLOSE
		// makes 100% looking like in 120dpi
		// webView.getSettings().setDefaultZoom(ZoomDensity.FAR);
		webView.getSettings().setSupportZoom(true);
		// webView.getSettings().setBuiltInZoomControls(true);

		webView.setScrollBarStyle(0);// 滚动条风格，为0就是不给滚动条留空间，滚动条覆盖在网页上
		webView.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
//				Message message = new Message();
//				message.obj = url;
				view.freeMemory();
				ActivityUtils.getInstance().leftIN_rightOUT_Transition(TabAppCenterActivity.this, TabAppCenterActivity.this,
						WebviewActivity.class, "uri", url);
				return true;
			}// 重写点击动作,用webview载入

			// @Override
			// public void onReceivedSslError(WebView view, SslErrorHandler
			// handler, SslError error) {
			// super.onReceivedSslError(view, handler, error);
			// handler.proceed();
			// }
		});
		webView.setWebChromeClient(new WebChromeClient() {
			public void onProgressChanged(WebView view, int progress) {// 载入进度改变而触发
				super.onProgressChanged(view, progress);
			}
		});
		webView.setOnTouchListener(new View.OnTouchListener() {
			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				return false;
			}
		});

	}
	
	
	public boolean onKeyDown(int keyCode, KeyEvent event) {// 捕捉返回键
		if ((keyCode == KeyEvent.KEYCODE_BACK)) {
			ActivityUtils.getInstance().back_leftOUT_rightIN_Transition(TabAppCenterActivity.this, getApplicationContext());
		}
		return true;
	}


}
